<template>
<el-dialog title="采购申请" :close-on-click-modal="false" :visible.sync="visible" width="90%">
    <el-form :model="dataForm" :inline="true" ref="dataForm" @keyup.enter.native="dataFormSubmit()">
        <el-form-item label="申请人" prop="applicant">
            <el-input :disabled="true" v-model="dataForm.applicant" placeholder="申请人"></el-input>
        </el-form-item>
        <el-form-item label="申请时间" prop="applyDate">
            <el-date-picker :disabled="true" v-model="dataForm.applyDate" type="date" placeholder="选择日期"></el-date-picker>
        </el-form-item>
        <el-form-item label="申请状态" prop="status">
            <el-select v-model="dataForm.status" placeholder="请选择" :disabled="true">
                <el-option v-for="item in statusList" :key="item.id" :label="item.desc" :value="item.id"></el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="备注" prop="note">
            <el-input v-model="dataForm.note" placeholder="备注"></el-input>
        </el-form-item>
    </el-form>
    <el-table :data="dataForm.bookList" border @selection-change="selectionChangeHandle" style="width: 100%;">
        <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
        <el-table-column prop="img" header-align="center" align="center" label="封面" width="120">
            <template slot-scope="scope">
                <img v-if="scope.row.imgUrl" style="width: 100px; height: 100px" :src="scope.row.imgUrl" />
                <span v-else></span>
            </template>
        </el-table-column>
        <el-table-column prop="name" header-align="center" align="center" label="图书名称"></el-table-column>
        <el-table-column prop="type" header-align="center" align="center" label="分类" width="50"></el-table-column>
        <el-table-column prop="isbn" header-align="center" align="center" label="ISBN" width="130"></el-table-column>
        <el-table-column prop="author" header-align="center" align="center" label="作者"></el-table-column>
        <el-table-column prop="press" header-align="center" align="center" label="出版社"></el-table-column>
        <el-table-column prop="publishDate" header-align="center" align="center" label="出版时间" width="100">
            <template slot-scope="scope">{{scope.row.publishDate | formatYearMonth}}</template>
        </el-table-column>
        <el-table-column prop="language" header-align="center" align="center" label="语言" width="50"></el-table-column>
        <el-table-column prop="price" header-align="center" align="center" label="定价" width="80">
            <template slot-scope="scope">￥{{scope.row.price | formatPrice}}</template>
        </el-table-column>
        <el-table-column prop="num" header-align="center" align="center" label="采购数量">
            <template slot-scope="scope">
                <el-input v-model="scope.row.num"></el-input>
            </template>
        </el-table-column>
    </el-table>
    <span slot="footer" class="dialog-footer">
        <el-button @click="visible = false">取消</el-button>
        <el-button type="primary" @click="dataFormSubmit()">审核通过</el-button>
        <el-button type="danger" @click="visible = false">退回</el-button>
    </span>
</el-dialog>
</template>

<script>
export default {
    data() {
        return {
            statusList: [{
                id: 1,
                desc: "待审核"
            }],
            visible: false,
            dataForm: {
                id: 0,
                applicant: "",
                applyDate: new Date(),
                status: 1,
                note: "",
                bookList: []
            }
        };
    },
    methods: {
        init(data) {
            this.visible = true;
            this.dataForm = data;
            this.dataForm.bookList.forEach(function (item) {
                if (item.img) {
                    item.imgUrl =
                        "http://localhost:8080/wenyuan/generator/tbook/img/" + item.id;
                }
            });
        },
        // 表单提交
        dataFormSubmit() {
            this.$http({
                url: this.$http.adornUrl(`/generator/tpurchaseapplication/check/` + this.dataForm.id),
                method: "post"
            }).then(({
                data
            }) => {
                if (data && data.code === 0) {
                    this.$message({
                        message: "已审核",
                        type: "success",
                        duration: 1500,
                        onClose: () => {
                            this.visible = false;
                            this.$emit("refreshDataList");
                        }
                    });
                } else {
                    this.$message.error(data.msg);
                }
            });
        },
        selectionChangeHandle() {}
    }
};
</script>
